//-----------------------------------------------------------------------------
// Name: Barn.cpp
// Auth: Robert Darty & Dante Ratto
// Desc: Barn Code
//-----------------------------------------------------------------------------

#include "Barn.h"

#include "SharedConstants.h"

#include "corona/corona.h"

#include <GL/glut.h>
#include <math.h>

//-----------------------------------------------------------------------------
// Globals:
//-----------------------------------------------------------------------------
cBarn gBarn;


//-----------------------------------------------------------------------------
// Functions:
//-----------------------------------------------------------------------------
cBarn* GetBarn()
{
	return &gBarn;
}

//-----------------------------------------------------------------------------
// class cBarn:
//-----------------------------------------------------------------------------
cBarn::cBarn() :
	mXPosition(0),
	mZPosition(0),
	mRotate(0)
{

}

cBarn::~cBarn()
{
}

//Moves barn to position
void cBarn::Move(float x, float z)
{
	mXPosition = x;
	mZPosition = z;
}

//Rotates barn
void cBarn::Rotate( float r )
{
	mRotate = r;
}

//Draws barn
void cBarn::Draw()
{
	glPushMatrix();
		glTranslatef(mXPosition, 0, mZPosition);
		glDisable(GL_CULL_FACE);

	glRotatef(mRotate, 0.0f, 1.0f, 0.0f);
	glColor3fv(kColorBarn);

	glBegin(GL_QUADS);

	//floor
	glVertex3f(3.5f, 0.0f, 3.0f);
	glVertex3f(3.5f, 0.0f, -3.0f);
	glVertex3f(-3.5f, 0.0f, -3.0f);
	glVertex3f(-3.5f, 0.0f, 3.0f);

	//right
	glVertex3f(3.5f, 5.0f, -3.0f);
	glVertex3f(3.5f, 5.0f, 3.0f);
	glVertex3f(3.5f, 0.0f, 3.0f);
	glVertex3f(3.5f, 0.0f, -3.0f);

	//left
	glVertex3f(-3.5f, 5.0f, 3.0f);
	glVertex3f(-3.5f, 5.0f, -3.0f);
	glVertex3f(-3.5f, 0.0f, -3.0f);
	glVertex3f(-3.5f, 0.0f, 3.0f);

	//front top
	glVertex3f(3.5f, 5.0f, 3.0f);
	glVertex3f(3.5f, 5.0f, -3.0f);
	glVertex3f(3.5f, 0.0f, -3.0f);
	glVertex3f(3.5f, 0.0f, 3.0f);

	//front left
	glVertex3f(-2.5f, 5.0f, 3.0f);
	glVertex3f(-3.5f, 5.0f, 3.0f);
	glVertex3f(-3.5f, 0.0f, 3.0f);
	glVertex3f(-2.5f, 0.0f, 3.0f);

	//front right
	glVertex3f(3.5f, 5.0f, 3.0f);
	glVertex3f(2.5f, 5.0f, 3.0f);
	glVertex3f(2.5f, 0.0f, 3.0f);
	glVertex3f(3.5f, 0.0f, 3.0f);

	//right door open
	//glColor3f(0.0f, 0.0f, 0.0f);
	//glVertex3f(5.0f, 0.0f, 5.0f);
	//glVertex3f(5.0f, 4.0f, 5.0f);
	//glVertex3f(2.5f, 4.0f, 3.0f);
	//glVertex3f(2.5f, 0.0f, 3.0f);

	//right door closed
	glColor3fv(kColorBlack);
	glVertex3f(2.5f, 0.0f, 3.0f);
	glVertex3f(2.5f, 4.0f, 3.0f);
	glVertex3f(0.0f, 4.0f, 3.0f);
	glVertex3f(0.0f, 0.0f, 3.0f);

	//left door open
	//glColor3f(0.0f, 0.0f, 0.0f);
	//glVertex3f(-2.5f, 0.0f, 3.0f);
	//glVertex3f(-2.5f, 4.0f, 3.0f);
	//glVertex3f(-5.0f, 4.0f, 5.0f);
	//glVertex3f(-5.0f, 0.0f, 5.0f);

	//left door closed
	glColor3fv(kColorBlack);
	glVertex3f(0.0f, 0.0f, 3.0f);
	glVertex3f(0.0f, 4.0f, 3.0f);
	glVertex3f(-2.5f, 4.0f, 3.0f);
	glVertex3f(-2.5f, 0.0f, 3.0f);

	//back
	glColor3fv(kColorBarn);
	glVertex3f(3.5f, 5.0f, -3.0f);
	glVertex3f(-3.5f, 5.0f, -3.0f);
	glVertex3f(-3.5f, 0.0f, -3.0f);
	glVertex3f(3.5f, 0.0f, -3.0f);

	//front roof
	glVertex3f(3.5f, 5.0f, 3.0f);
	glVertex3f(-3.5f, 5.0f, 3.0f);
	glVertex3f(-3.5f, 4.0f, 3.0f);
	glVertex3f(3.5f, 4.0f, 3.0f);

	//roof front right
	glVertex3f(2.0f, 5.0f, 3.0f);
	glVertex3f(2.0f, 8.0f, 3.0f);
	glVertex3f(1.5f, 8.0f, 3.0f);
	glVertex3f(1.5f, 5.0f, 3.0f);

	//roof front left
	glVertex3f(-1.5f, 5.0f, 3.0f);
	glVertex3f(-1.5f, 8.0f, 3.0f);
	glVertex3f(-2.0f, 8.0f, 3.0f);
	glVertex3f(-2.0f, 5.0f, 3.0f);

	//roof back
	glVertex3f(2.0f, 8.0f, -3.0f);
	glVertex3f(2.0f, 5.0f, -3.0f);
	glVertex3f(-2.0f, 5.0f, -3.0f);
	glVertex3f(-2.0f, 8.0f, -3.0f);

	//roof door
	glColor3fv(kColorBlack);
	glVertex3f(-1.5f, 5.5f, 3.0f);
	glVertex3f(-1.5f, 7.5f, 3.0f);
	glVertex3f(-4.0f, 7.5f, 5.0f);
	glVertex3f(-4.0f, 5.5f, 5.0f);

	//roof front top
	glColor3fv(kColorBarn);
	glVertex3f(1.5f, 7.5f, 3.0f);
	glVertex3f(1.5f, 8.0f, 3.0f);
	glVertex3f(-1.5f, 8.0f, 3.0f);
	glVertex3f(-1.5f, 7.5f, 3.0f);

	//roof front bottom
	glVertex3f(1.5f, 5.0f, 3.0f);
	glVertex3f(1.5f, 5.5f, 3.0f);
	glVertex3f(-1.5f, 5.5f, 3.0f);
	glVertex3f(-1.5f, 5.0f, 3.0f);

	//roof bottom outside right side
	glVertex3f(3.5f, 5.0f, -3.0f);
	glVertex3f(3.5f, 5.0f, 3.0f);
	glVertex3f(4.0f, 5.0f, 3.0f);
	glVertex3f(4.0f, 5.0f, -3.0f);

	//roof bottom outside left side
	glVertex3f(-3.5f, 5.0f, -3.0f);
	glVertex3f(-3.5f, 5.0f, 3.0f);
	glVertex3f(-4.0f, 5.0f, 3.0f);
	glVertex3f(-4.0f, 5.0f, -3.0f);

	//roof outside right side
	glVertex3f(4.0f, 5.0f, 3.0f);
	glVertex3f(4.0f, 5.0f, -3.0f);
	glVertex3f(2.0f, 8.0f, -3.0f);
	glVertex3f(2.0f, 8.0f, 3.0f);

	//roof outside left side
	glVertex3f(-2.0f, 8.0f, 3.0f);
	glVertex3f(-2.0f, 8.0f, -3.0f);
	glVertex3f(-4.0f, 5.0f, -3.0f);
	glVertex3f(-4.0f, 5.0f, 3.0f);

	//roof inside left side
	glVertex3f(0.0f, 9.0f, 3.0f);
	glVertex3f(0.0f, 9.0f, -3.0f);
	glVertex3f(-2.0f, 8.0f, -3.0f);
	glVertex3f(-2.0f, 8.0f, 3.0f);

	//roof outside right side
	glVertex3f(4.0f, 5.0f, 3.0f);
	glVertex3f(4.0f, 5.0f, -3.0f);
	glVertex3f(2.0f, 8.0f, -3.0f);
	glVertex3f(2.0f, 8.0f, 3.0f);

	//roof inside right side
	glVertex3f(2.0f, 8.0f, 3.0f);
	glVertex3f(2.0f, 8.0f, -3.0f);
	glVertex3f(0.0f, 9.0f, -3.0f);
	glVertex3f(0.0f, 9.0f, 3.0f);

	glEnd();

	glBegin(GL_TRIANGLES);

	//roof front right
	glVertex3f(4.0f, 5.0f, 3.0f);
	glVertex3f(2.0f, 8.0f, 3.0f);
	glVertex3f(2.0f, 5.0f, 3.0f);

	//roof front left
	glVertex3f(-2.0f, 5.0f, 3.0f);
	glVertex3f(-2.0f, 8.0f, 3.0f);
	glVertex3f(-4.0f, 5.0f, 3.0f);

	//roof top front
	glVertex3f(2.0f, 8.0f, 3.0f);
	glVertex3f(0.0f, 9.0f, 3.0f);
	glVertex3f(-2.0f, 8.0f, 3.0f);

	//roof top back
	glVertex3f(-2.0f, 8.0f, -3.0f);
	glVertex3f(0.0f, 9.0f, -3.0f);
	glVertex3f(2.0f, 8.0f, -3.0f);

	//roof back left
	glVertex3f(2.0f, 5.0f, -3.0f);
	glVertex3f(2.0f, 8.0f, -3.0f);
	glVertex3f(4.0f, 5.0f, -3.0f);

	//roof back right
	glVertex3f(-4.0f, 5.0f, -3.0f);
	glVertex3f(-2.0f, 8.0f, -3.0f);
	glVertex3f(-2.0f, 5.0f, -3.0f);

	glEnd();

	glBegin(GL_LINES);
	glColor3fv(kColorBarn);
	glVertex3f(0.0f, 5.0f, 3.1f);
	glVertex3f(0.0f, 0.0f, 3.1f);
	glEnd();

	glPopMatrix();
	glEnable(GL_CULL_FACE);
}
